//
//  HomeViewController.m
//  chanyouji
//
//  Created by xiacheng on 16/8/17.
//  Copyright © 2016年 chanyouji. All rights reserved.
//

#import "HomeViewController.h"
#import "AFNetworking.h"
#import "HeadScrollView.h"
#import "HeaderModel.h"
#import "Common.h"
@interface HomeViewController ()
@property (nonatomic,strong)HeadScrollView *headScroll;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"首页";
    self.navigationController.navigationBarHidden = YES;
    [self loadData];
    [self creatUI];
    
    // Do any additional setup after loading the view.
}
#pragma mark ----请求数据
- (void)loadData {
    //请求头部广告图片和文字
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *urlStr = @"http://q.chanyouji.com/api/v1/adverts.json?first_launch=false";
    [manager GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSMutableArray *modelArry  = [NSMutableArray array];
        NSArray *imgArr = responseObject[@"data"];
        for (NSDictionary *dic in imgArr) {
            NSDictionary *photoDic = dic[@"photo"];
            NSString *photo_url = photoDic[@"photo_url"];
            [modelArry addObject:photo_url];
        }
        //赋值给model(PS:此处有点多余，当数据多起来时方便修改，下面的复制操作改为set方法，方便复制多个数据)
        HeaderModel *model = [[HeaderModel alloc]init];
        model.headURLArr = modelArry;
        self.headScroll = [[HeadScrollView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        self.headScroll.headModel = model;
        [self.view addSubview:_headScroll];
        
            
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
    

}
#pragma mark-----  搭建界面框架
- (void)creatUI {
    UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,headAdvantiseHeight, kScreenWidth, 40)];
    searchBar.barStyle =  UIBarStyleBlack;
    
    searchBar.barTintColor = [UIColor whiteColor];
  
    searchBar.text = @"搜索目的地、游记与用户";
   
    
    
    [self.view addSubview:searchBar];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
